package servlet;

import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.servlet.http.HttpServletRequest;

import service.IServiceManager;
import service.exception.ServiceException;

import bean.Customer;
import bean.User;
import bean.UserProfile;
import business.user.UserManagement;

@SuppressWarnings("deprecation")
public class CustomerAction {
	private Customer customerA;
	private User userA;

	public String Register(){
    	   HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
    	   FacesContext context=FacesContext.getCurrentInstance();
    	   ValueBinding customer_binding=context.getApplication().createValueBinding("#{customer}");
    	   ValueBinding user_binding=context.getApplication().createValueBinding("#{user}");
    	   customerA=(Customer)customer_binding.getValue(context);
    	   userA=(User)user_binding.getValue(context);
    	   System.out.println(customerA.getName());
    	   System.out.println(customerA.getAddress());
    	   System.out.println(customerA.getTelephone());
    	   System.out.println(userA.getAccount());
    	   System.out.println(userA.getPassword());
    	   System.out.println();
    	   UserProfile customer=new UserProfile(userA, customerA);  	   
    	   IServiceManager serviceMgn = new UserManagement(request);
    	   try {
    		   customer=serviceMgn.execute(UserManagement.SERVICE_REGISTER_CUSTOMER, customer);
		} catch (ServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	   /*Register customer here using DAO function*/
    	   return null;
       }
}
